import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:ytbusiness/config/style.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';
import 'package:ytbusiness/widgets/widgets.dart';

//修理厂已完成
class ProcurementDone extends StatefulWidget {
  @override
  _ProcurementDoneState createState() => _ProcurementDoneState();
}

class _ProcurementDoneState extends State<ProcurementDone> {
  List<String> titleList = ["订单编号", "订单时间", "VIN", "车辆型号"];
  List<String> contentList = [
    "183819993923",
    "2020-11-23 15:00",
    "LVHQO6652G6043020",
    "本田 DJFH 2012"
  ];
  List<bool> isShow = []; //是否隐藏

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    titleList.forEach((element) {
      isShow.add(false);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: YTStyle.bgColor,
      appBar: customAppBar(context, title: "已完成", elevation: 0.5),
      body: Stack(
        children: [
          CustomScrollView(
            slivers: [
              SliverToBoxAdapter(
                child: Container(
                  color: Colors.white,
                  padding: EdgeInsets.only(
                      top: setWidth(10),
                      left: setWidth(15),
                      right: setWidth(15)),
                  child: ListView.builder(
                      physics: NeverScrollableScrollPhysics(),
                      shrinkWrap: true,
                      itemCount: titleList.length,
                      itemBuilder: (context, index) {
                        return Container(
                          margin: EdgeInsets.only(
                              top: setWidth(10), bottom: setWidth(10)),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.start,
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Container(
                                child: Text(
                                  "${titleList[index]}:",
                                  style: TextStyle(
                                      color: Color(0xff999999),
                                      fontSize: setWidth(15)),
                                ),
                                width: setWidth(90),
                              ),
                              Expanded(
                                child: Container(
                                  child: Text(
                                    "${contentList[index]}",
                                    style: TextStyle(
                                        color: Color(0xff333333),
                                        fontSize: setWidth(15)),
                                  ),
                                ),
                              ),
                            ],
                          ),
                        );
                      }),
                ),
              ),
              //订单状态
              SliverToBoxAdapter(
                child: Container(
                  color: Colors.white,
                  padding: EdgeInsets.only(
                      top: setWidth(10),
                      left: setWidth(15),
                      right: setWidth(15),
                      bottom: setWidth(15)),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Container(
                        child: Text(
                          "订单状态:",
                          style: TextStyle(
                              color: Color(0xff999999), fontSize: setWidth(15)),
                        ),
                        width: setWidth(90),
                      ),
                      Expanded(
                        child: Container(
                          child: Text(
                            "待发货",
                            style: TextStyle(
                                color: Color(0xffFF4D4D),
                                fontSize: setWidth(15)),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
              //已发货信息
              SliverToBoxAdapter(
                child: Container(
                  margin: EdgeInsets.only(top: setWidth(15)),
                  padding: EdgeInsets.only(top: setWidth(18)),
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.only(
                          topLeft: Radius.circular(4),
                          topRight: Radius.circular(4))),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Container(
                        padding: EdgeInsets.only(left: setWidth(15)),
                        child: Text(
                          "询价信息",
                          style: TextStyle(
                              color: Color(0xff333333),
                              fontSize: setWidth(15),
                              fontWeight: FontWeight.w500),
                        ),
                      ),
                      Container(
                        margin: EdgeInsets.only(top: setWidth(13)),
                        height: setWidth(0.5),
                        color: Color(0xffF0F0F0),
                      ),
                    ],
                  ),
                ),
              ),
              //已发货列表
              SliverToBoxAdapter(
                child: ListView.builder(
                    physics: NeverScrollableScrollPhysics(),
                    shrinkWrap: true,
                    itemCount: titleList.length,
                    itemBuilder: (context, key) {
                      return Container(
                        margin: EdgeInsets.only(bottom: setWidth(12)),
                        padding: EdgeInsets.only(
                            top: setWidth(22), bottom: setWidth(15)),
                        color: Colors.white,
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.start,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Container(
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.start,
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Container(
                                    height: setWidth(58),
                                    width: setWidth(58),
                                    decoration: BoxDecoration(
                                        color: Color(0xffC4C4C4),
                                        borderRadius: BorderRadius.circular(4)),
                                  ),
                                  SizedBox(
                                    width: setWidth(10),
                                  ),
                                  Expanded(
                                      child: Column(
                                    mainAxisAlignment: MainAxisAlignment.start,
                                    crossAxisAlignment:
                                        CrossAxisAlignment.start,
                                    children: [
                                      Container(
                                        child: Text(
                                          "永达汽贸 [杭州]",
                                          style: TextStyle(
                                              color: Color(0xff333333),
                                              fontSize: setWidth(16),
                                              fontWeight: FontWeight.w500),
                                        ),
                                      ),
                                      SizedBox(
                                        height: setWidth(10),
                                      ),
                                      Row(
                                        children: [
                                          link(
                                              image: "black_kefu.png",
                                              title: "在线联系",
                                              phone: "10086"),
                                          SizedBox(
                                            width: setWidth(10),
                                          ),
                                          link(
                                              image: "black_dianhua.png",
                                              title: "电话联系",
                                              phone: "10086"),
                                        ],
                                      )
                                    ],
                                  ))
                                ],
                              ),
                              padding: EdgeInsets.only(
                                  left: setWidth(15), right: setWidth(15)),
                              margin: EdgeInsets.only(bottom: setWidth(14)),
                            ),

                            //商品列表
                            ListView.builder(
                                physics: NeverScrollableScrollPhysics(),
                                shrinkWrap: true,
                                itemCount: isShow[key]
                                    ? titleList.length
                                    : (titleList.length > 0 ? 1 : 0),
                                itemBuilder: (context, index) {
                                  return _goodsItem(key: key, index: index);
                                }),
                            SizedBox(
                              height: setWidth(20),
                            ),

                            //隐藏显示
                            GestureDetector(
                              behavior: HitTestBehavior.opaque,
                              onTap: () {
                                setState(() {
                                  isShow[key] = !isShow[key];
                                });
                              },
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.center,
                                children: [
                                  Container(
                                    width: setWidth(92),
                                    height: setWidth(1),
                                    child: Image.asset(
                                      "assets/images/left_line.png",
                                      fit: BoxFit.cover,
                                    ),
                                  ),
                                  SizedBox(
                                    width: setWidth(12),
                                  ),
                                  Container(
                                    child: Text(
                                      isShow[key] ? "收起" : "展开",
                                      style: TextStyle(
                                          color: Color(0xff8590A6),
                                          fontSize: setSp(15)),
                                    ),
                                  ),
                                  Container(
                                    width: setWidth(8),
                                    height: setWidth(6),
                                    child: Image.asset(
                                      isShow[key]
                                          ? "assets/images/black_shouqi.png"
                                          : "assets/images/gary_done.png",
                                      fit: BoxFit.cover,
                                    ),
                                  ),
                                  SizedBox(
                                    width: setWidth(12),
                                  ),
                                  Container(
                                    width: setWidth(92),
                                    height: setWidth(1),
                                    child: Image.asset(
                                      "assets/images/right_line.png",
                                      fit: BoxFit.cover,
                                    ),
                                  ),
                                ],
                              ),
                            ),
                            SizedBox(
                              height: setWidth(20),
                            ),
                            //总金额
                            Row(
                              mainAxisAlignment: MainAxisAlignment.end,
                              children: [
                                Container(
                                  child: RichText(
                                      text: TextSpan(children: [
                                    TextSpan(
                                        text: "共",
                                        style: TextStyle(
                                            color: Color(0xff989898),
                                            fontSize: setSp(14))),
                                    TextSpan(
                                        text: "1",
                                        style: TextStyle(
                                            color: Color(0xff323232),
                                            fontSize: setSp(14))),
                                    TextSpan(
                                        text: "件商品",
                                        style: TextStyle(
                                            color: Color(0xff989898),
                                            fontSize: setSp(14))),
                                  ])),
                                ),
                                SizedBox(
                                  width: setWidth(20),
                                ),
                                Container(
                                  child: RichText(
                                      text: TextSpan(children: [
                                    TextSpan(
                                        text: "总金额:",
                                        style: TextStyle(
                                            color: Color(0xff323232),
                                            fontSize: setSp(14))),
                                    TextSpan(
                                        text: "￥",
                                        style: TextStyle(
                                            color: Color(0xffFF6701),
                                            fontSize: setSp(14))),
                                    TextSpan(
                                        text: "1259.00",
                                        style: TextStyle(
                                            color: Color(0xffFF6701),
                                            fontSize: setSp(18),
                                            fontWeight: FontWeight.w600)),
                                  ])),
                                ),
                                SizedBox(
                                  width: setWidth(15),
                                ),
                              ],
                            ),
                            Container(
                              height: setWidth(10),
                              color: Color(0xffF0F0F0),
                              width: setWidth(375),
                              margin: EdgeInsets.only(top: setWidth(10)),
                            ),
                            //确认发货
                            _confirmDeliver(),
                          ],
                        ),
                      );
                    }),
              ),
              SliverToBoxAdapter(
                child: SizedBox(
                  height: setWidth(60),
                ),
              )
            ],
          ),
          //总金额
          Align(
            alignment: Alignment.bottomCenter,
            child: Container(
              padding: EdgeInsets.only(left: setWidth(15), right: setWidth(15)),
              height: setWidth(60),
              decoration: BoxDecoration(
                color: Colors.white,
                border: Border(
                    top: BorderSide(
                        color: Color(0xffD6DADB), width: setWidth(0.5))),
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.end,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Container(
                    child: RichText(
                        text: TextSpan(children: [
                      TextSpan(
                          text: "合计:",
                          style: TextStyle(
                              color: Color(0xff323232), fontSize: setSp(14))),
                      TextSpan(
                          text: "￥",
                          style: TextStyle(
                              color: Color(0xffFF6701), fontSize: setSp(14))),
                      TextSpan(
                          text: "2518.00",
                          style: TextStyle(
                              color: Color(0xffFF6701),
                              fontSize: setSp(18),
                              fontWeight: FontWeight.w600)),
                    ])),
                  ),
                ],
              ),
            ),
          )
        ],
      ),
    );
  }

  //商品
  Widget _goodsItem({int key, int index}) {
    return Container(
      color: Colors.white,
      padding: EdgeInsets.only(left: setWidth(15), right: setWidth(15)),
      margin: EdgeInsets.only(bottom: setWidth(12), top: setWidth(10)),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                height: setWidth(90),
                width: setWidth(90),
                decoration: BoxDecoration(
                    color: Color(0xffC4C4C4),
                    borderRadius: BorderRadius.circular(6)),
              ),
              SizedBox(
                width: setWidth(10),
              ),
              Expanded(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.start,
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Expanded(
                          child: Container(
                            child: Text(
                              "前挡泥板-右后翼子板前挡泥板",
                              style: TextStyle(
                                  color: Color(0xff323232),
                                  fontSize: setSp(15)),
                              maxLines: 2,
                              overflow: TextOverflow.ellipsis,
                            ),
                          ),
                        ),
                      ],
                    ),
                    //属性
                    Row(
                      children: [
                        Expanded(
                          child: Container(
                            margin: EdgeInsets.only(top: setWidth(5)),
                            child: Text(
                              "属性：原厂原包",
                              style: TextStyle(
                                  color: Color(0xff989898),
                                  fontSize: setSp(14)),
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                            ),
                          ),
                        ),
                        Expanded(
                          child: Container(
                            margin: EdgeInsets.only(top: setWidth(5)),
                            child: Text(
                              "报价:OEM",
                              style: TextStyle(
                                  color: Color(0xffFF6701),
                                  fontSize: setSp(14)),
                              maxLines: 1,
                              overflow: TextOverflow.ellipsis,
                            ),
                          ),
                        ),
                      ],
                    ),
                    SizedBox(
                      height: setWidth(30),
                    ),

                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Container(
                          child: RichText(
                              text: TextSpan(children: [
                            TextSpan(
                                text: "￥",
                                style: TextStyle(
                                    color: Color(0xffFF6701),
                                    fontSize: setSp(14))),
                            TextSpan(
                                text: "1259.00",
                                style: TextStyle(
                                    color: Color(0xffFF6701),
                                    fontSize: setSp(18),
                                    fontWeight: FontWeight.w600)),
                          ])),
                        ),
                        Container(
                          margin: EdgeInsets.only(top: setWidth(5)),
                          child: Text("x1",
                              style: TextStyle(
                                  color: Color(0xff323232),
                                  fontSize: setSp(14))),
                        ),
                      ],
                    ),
                  ],
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }

  //确认发货
  Widget _confirmDeliver() {
    return Container(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            margin: EdgeInsets.only(
                top: setWidth(20),
                bottom: setWidth(20),
                left: setWidth(15),
                right: setWidth(15)),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  child: Text(
                    "发货信息",
                    style: TextStyle(
                        color: Color(0xff323232),
                        fontSize: setSp(16),
                        fontWeight: FontWeight.w600),
                  ),
                ),
                //发货时间
                Container(
                  margin:
                      EdgeInsets.only(bottom: setWidth(18), top: setWidth(20)),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Container(
                        width: setWidth(64),
                        child: Text(
                          "发货时间:",
                          style: TextStyle(
                              color: Color(0xff323232), fontSize: setSp(14)),
                        ),
                      ),
                      Expanded(
                        child: Container(
                          child: Text("2020-11-27 11:21",
                              style: TextStyle(
                                  color: Color(0xff323232),
                                  fontSize: setSp(14))),
                        ),
                      ),
                    ],
                  ),
                ),
                //快递方式
                Container(
                  margin: EdgeInsets.only(bottom: setWidth(18)),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Container(
                        width: setWidth(64),
                        child: Text(
                          "快递方式:",
                          style: TextStyle(
                              color: Color(0xff323232), fontSize: setSp(14)),
                        ),
                      ),
                      Expanded(
                        child: Container(
                          child: Text("韵达",
                              style: TextStyle(
                                  color: Color(0xff323232),
                                  fontSize: setSp(14))),
                        ),
                      ),
                    ],
                  ),
                ),
                //快递单号
                Container(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Container(
                        width: setWidth(64),
                        alignment: Alignment.centerLeft,
                        child: Text(
                          "快递单号:",
                          style: TextStyle(
                              color: Color(0xff323232), fontSize: setSp(14)),
                        ),
                      ),
                      Expanded(
                        child: Container(
                          child: Text("2020154654546546665",
                              style: TextStyle(
                                  color: Color(0xff323232),
                                  fontSize: setSp(14))),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
